function outerFunc() {
  let outerVar = 'I am outside!'

  function innerFunc() {
    console.log(outerVar) // => logs "I am outside!"
  }

  return innerFunc
}

function exec() {
  const myInnerFunc = outerFunc()
  myInnerFunc()
}

exec()

function fn1() {
  var a = 2
  var fn2 = function() {
    a++
    console.log(a)
  }
  return fn2
}

var f = fn1()
f()
f()

var a = 10
function foo(){
  console.log(a)
}

function bar() {
  var a = 20
  foo()
}

bar()

for (var i = 0; i < 3; i++) {
  setTimeout(function log() {
    console.log(i) // What is logged?
  }, 1000)
}

let i
for (i = 0; i < 3; i++) {
  const log = () => {
    console.log(i)
  }
  setTimeout(log, 100)
}

function createIncrement() {
  let count = 0
  function increment() {
    count++
    console.log(count)
  }
  let message = `Count is ${count}`
  function log() {
    console.log(message)
  }

  return [increment, log]
}
const [increment, log] = createIncrement()
increment()
increment()
increment()
log() // What is logged?
